package cn.com.wanywhn.servlet;

import cn.com.wanywhn.bean.Message;
import cn.com.wanywhn.dao.MessageDAO;
import cn.com.wanywhn.daoImpl.MessageDAOImpl;
import cn.com.wanywhn.util.DBConnection;
import sun.rmi.server.Dispatcher;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.Connection;

@WebServlet(name = "ServletDeleteMessage")
public class ServletDeleteMessage extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        System.err.println("test");
        String messageID = request.getParameter("messageID");


        MessageDAO messageDAO=new MessageDAOImpl();
        messageDAO.deleteMessage(Integer.parseInt(messageID));

//        RequestDispatcher dispatcher;
//        ServletContext servletContext = getServletContext();
//        dispatcher=servletContext.getRequestDispatcher("/mesgList.jsp");
        response.sendRedirect("/msgList.jsp");

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
